package com.datastructure.algorithm.violencematch;

import java.util.ArrayList;
import java.util.List;

//暴力匹配算法
public class ViolenceMatch {
    public static void main(String[] args) {

    }

    public static int violenceMatch(String s1,String s2){
        char [] char1=s1.toCharArray();
        char [] char2=s2.toCharArray();
        int char1Length=char1.length;
        int char2Length=char2.length;
        int i = 0;
        int j = 0;
        List<Integer> strings = new ArrayList<>();
        while (i < char1Length&&j < char2Length){
            if(char1[i]==char2[j]){
                i++;
                j++;
            } else {
                i = i -j+1;
                j = 0;
            }
        }
        if(j==char2Length){
            return i - j;
        } else {
            return -1;
        }
    }
}


